package it.koutifaris.travianmap.tile.boundscache;

import it.koutifaris.travianmap.tile.TileBounds;
import it.koutifaris.travianmap.tile.bounds.DefaultTileBounds;
import junit.framework.Assert;
import android.test.AndroidTestCase;

public class AbstractBoundsCacheTest extends AndroidTestCase {

	private BoundsCache boundsCache;

	protected void setBoundsCache(BoundsCache boundsCache) {
		this.boundsCache = boundsCache;
	}

	public void testOrigin() {
		addBounds();

		Assert.assertTrue(boundsCache.containsPoint(-3, -3));
	}

	public void testEdgeA() {
		addBounds();

		Assert.assertTrue(boundsCache.containsPoint(-1, -1));
	}

	public void testEdgeB() {
		addBounds();

		Assert.assertTrue(boundsCache.containsPoint(2, 2));
	}

	public void testPointInsideLeft() {
		addBounds();

		Assert.assertTrue(boundsCache.containsPoint(-1, -2));
	}

	public void testPointInsideRight() {
		addBounds();

		Assert.assertTrue(boundsCache.containsPoint(1, 1));
	}

	public void testPointOutside() {
		addBounds();

		Assert.assertFalse(boundsCache.containsPoint(3, 4));
	}

	public void testRemoveBounds() {
		addBounds();
		boundsCache.removeBounds(testTileBoundsA());

		Assert.assertFalse(boundsCache.containsPoint(-1, -2));
	}

	private void addBounds() {
		boundsCache.addBounds(testTileBoundsA());
		boundsCache.addBounds(testTileBoundsB());
	}

	private TileBounds testTileBoundsA() {
		return DefaultTileBounds.builder()
				.setOrigin(-3, -3)
				.withSize(3, 3)
				.build();
	}

	private TileBounds testTileBoundsB() {
		return DefaultTileBounds.builder()
				.setOrigin(0, 0)
				.withSize(3, 3)
				.build();
	}
}
